package com.city.service.supervise.impl;

import com.city.domain.supervise.ImpLocation;
import com.city.repository.supervise.ImpLocationRepository;
import com.city.service.supervise.ImpLocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @author: Xln_z
 * @date: 2018/8/16
 * @decription:
 **/

@Service
public class ImpLocationServiceImpl implements ImpLocationService {

    @Autowired
    private ImpLocationRepository impLocationRepository;

    @Override
    public List<ImpLocation> getImpLocationLimit(Integer limitPage, Integer limitNum){
        return impLocationRepository.getImpLocationLimit((limitPage - 1) * limitNum, limitNum);
    }

    @Override
    public List<ImpLocation> getImpLocationLimit(Integer limitPage, Integer limitNum, String search){
        return impLocationRepository.getImpLocationLimit((limitPage - 1) * limitNum, limitNum, search);
    }


    @Override
    public List<ImpLocation> findAll(ImpLocation impLocation){
        //创建匹配器，即如何使用查询条件
        ExampleMatcher matcher = ExampleMatcher.matching() //构建对象
            .withMatcher("loname", ExampleMatcher.GenericPropertyMatchers.contains())
            .withMatcher("maname", ExampleMatcher.GenericPropertyMatchers.contains())
            .withMatcher("material", ExampleMatcher.GenericPropertyMatchers.contains()); //“模糊查询”的方式查询

        //创建实例
        Example<ImpLocation> ex = Example.of(impLocation, matcher);

        //查询
        return impLocationRepository.findAll(ex);
    }

    @Override
    public List<ImpLocation> getAll() {
        return impLocationRepository.getAll();
    }

    @Override
    public ImpLocation getByLoname(String loname) {
        return impLocationRepository.getByLoname(loname);
    }

    @Override
    public Long count(ImpLocation impLocation){
        //创建匹配器，即如何使用查询条件
        ExampleMatcher matcher = ExampleMatcher.matching() //构建对象
            .withMatcher("loname", ExampleMatcher.GenericPropertyMatchers.contains())
            .withMatcher("maname", ExampleMatcher.GenericPropertyMatchers.contains())
            .withMatcher("material", ExampleMatcher.GenericPropertyMatchers.contains());


        //创建实例
        Example<ImpLocation> ex = Example.of(impLocation, matcher);

        //查询
        return impLocationRepository.count(ex);
    }


}
